package com.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DBUtil {
	public static int getConnection(){
		try {
			Class.forName(DB.driver);
			Connection conn = DriverManager.getConnection(DB.url,DB.username,DB.password);
			DB.conn = conn;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	public static List<String> getTables(){
		Connection conn = DB.conn;
		String sql = "select   tabname   from   syscat.tables   where   tabschema   =   current   schema";
		List<String> tables = new ArrayList<String>();
		try {
			PreparedStatement pst = conn.prepareStatement(sql);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				System.out.println(rs.getString(1));
				tables.add(rs.getString(1));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tables;
	}
}
